home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / OpenDoc 1.2b2c1 / OpenDoc / OpenDoc Utilities / Interfaces / PlfmFile.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-01  |  9.1 KB  |  302 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        PlfmFile.h
  3.  
  4.     Contains:    Platform-file wrapper class
  5.  
  6.     Owned by:    Vincent Lo
  7.  
  8.     Copyright:    © 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <8>     9/27/96    EL        1353486: Add LockError to report how a file
  13.                                     is locked.
  14.          <7>    11.09.1996    NP        1386101: make public constants public
  15.          <5>     6/27/96    jpa        T10012: Changed kODMagicFileTypeChar to
  16.                                     avoid conflict w/developer
  17.          <4>     5/31/96    jpa        T10012: Added IsOpenDocDocument.
  18.          <3>     5/24/96    jpa        1.1MRD: pragma internal.
  19.          <2>      5/8/96    NP        1282265: saving as stationery looks like
  20.                                     document
  21.  
  22.     To Do:
  23.     In Progress:
  24.         
  25. */
  26.  
  27. #ifndef _PLFMFILE_
  28. #define _PLFMFILE_
  29.  
  30. #ifndef _ODTYPES_
  31. #include "ODTypes.h"
  32. #endif
  33.  
  34. #ifndef _PLFMDEF_
  35. #include "PlfmDef.h"
  36. #endif
  37.  
  38. #ifndef _ODMEMORY_
  39. #include "ODMemory.h"
  40. #endif
  41.  
  42. #ifndef _ITEXT_
  43. #include "IText.h"        /* For ODScriptCode type */
  44. #endif
  45.  
  46. #ifndef __FILES__
  47. #include <Files.h>
  48. #endif
  49.  
  50. //==============================================================================
  51. // Theory of Operation
  52. //==============================================================================
  53.  
  54. //==============================================================================
  55. // Constants
  56. //==============================================================================
  57.  
  58. const unsigned char kODMagicFileTypeChar    = 0xCD;
  59.                     // Magic 1st char of filetype ('Õ' or option-n, shift-o)
  60.  
  61. const    ODSShort    kODNoFileRefNum         = 0;
  62. const    ODSShort    kODMaxFileNameSize        = 31;
  63. const    ODULong        kODNoFileID                = 0;
  64.  
  65. /* Constants to specify the file fork GetLocalPaths should match */
  66. enum
  67. {
  68.     kODDataFork        = 0,
  69.     kODResourceFork    = 1
  70. };
  71. typedef short ODForkType;
  72.     
  73. //==============================================================================
  74. // Scalar Types
  75. //==============================================================================
  76.  
  77. typedef FSSpec        ODFileSpec;
  78. typedef short        ODFileRefNum;
  79. typedef ODSByte        ODFilePermission;
  80.  
  81. typedef ODFileRefNum    *ODFileRefNumPtr;
  82.  
  83. enum PFUniquifyAction { kSpecifyNewNameOnly, kRenameInPlace };
  84.  
  85. const    ODBoolean    kODTryCurrentName    = kODFalse;
  86. const    ODBoolean    kODForceNewName     = kODTrue;
  87.  
  88. const    ODSShort    kODNoResourceID = 0;
  89.  
  90. //==============================================================================
  91. // Classes defined in this interface
  92. //==============================================================================
  93.  
  94. class PlatformFile;
  95. class CWithActiveResources;        // private class
  96.  
  97.  
  98. //==============================================================================
  99. // PlatformFile
  100. //==============================================================================
  101.  
  102. #ifdef PRAGMA_INTERNAL_SUPPORTED
  103. #pragma internal on
  104. #endif
  105.  
  106. class PlatformFile
  107. {    
  108. public:
  109.  
  110.     PlatformFile();
  111.    ~PlatformFile();
  112.  
  113. // Methods you can call when the file is not open:
  114.     // pointing the PlatformFile at a physical file    and setting default opening permissions
  115.     // Specify() can only be called once on the object. If it is being called more than once,
  116.     // the behavior is unpredictable. If you want to work with a different file,
  117.     // you need to delete the current object and create a new one. 
  118.     ODNVMethod    void        Specify(const ODFileSpec* fileSpec);
  119.     ODNVMethod    void        SpecifyFromFile(PlatformFile* file);
  120.     ODNVMethod    void        SetAsciiName(const char* name);
  121.     inline        void        SetPermission(ODFilePermission filePermission);
  122.     // create/open/delete the file
  123.     inline        void        SetFileRefNum( ODFileRefNum );
  124.     ODNVMethod    void        Create(ODOSType creator, ODOSType fileType, ODScriptCode scriptCode);
  125.     ODNVMethod    void        Open();
  126.     ODNVMethod    void        Delete();
  127.  
  128.     // These are optional and simply optimize multiple resource calls
  129.     ODNVMethod    void        OpenResFile();
  130.     ODNVMethod    void        CloseResFile();
  131.     // create the resource fork (only to be used after Create).
  132.     ODNVMethod    void        CreateResFile();
  133.  
  134. // Methods you can call anytime after calling Specify or SetAsciiName
  135.     ODNVMethod    ODBoolean    IsEqualTo(PlatformFile* file);
  136.     ODNVMethod    ODError        LockError();
  137.     ODNVMethod    ODBoolean    IsLocked();
  138.     ODNVMethod    void        Lock();
  139.     ODNVMethod    void        Unlock();
  140.     ODNVMethod    ODBoolean    IsStationery();
  141.     ODNVMethod    void        SetStationery(ODBoolean isStationery);
  142.     ODNVMethod    void        SetCustomIcon(ODBoolean hasCustomIcon);
  143.     ODNVMethod    ODBoolean    HasCustomIcon();
  144.     ODNVMethod    ODBoolean    IsDirectory();
  145.     ODNVMethod    void        SetCustomIconFamily(ODIconFamily icons);
  146.     ODNVMethod    ODIconFamily    GetCustomIconFamily();
  147.     ODNVMethod    ODBoolean    Exists();
  148.     ODNVMethod    ODUShort    GetFInfoFlags();
  149.     ODNVMethod    void        SetFinderFlag(ODUShort flag);
  150.     ODNVMethod    void        UnsetFinderFlag(ODUShort flag);
  151.     
  152.     ODNVMethod    ODBoolean    IsOpenDocDocument( );
  153.     static        ODBoolean    IsOpenDocDocument( OSType type, OSType creator );
  154.     
  155.  
  156.     // Get & set the Desktop DB comment field
  157.     ODNVMethod    ODIText*    GetComments(ODIText* comments = kODNULL);
  158.     ODNVMethod    void        SetComments(ODIText* comments);
  159.  
  160.     ODNVMethod    void        FlushVolume();
  161.  
  162.     ODNVMethod    ODName*        GetName();
  163.     ODNVMethod    void        GetAsciiName(char* name,ODULong maxLength);
  164.     inline        ODULong        GetAsciiNameLength();
  165.     ODNVMethod    ODOSType    GetPlatformCreator();                    // Macintosh specific
  166.     ODNVMethod    void        SetPlatformCreator(ODOSType fileType);    // Macintosh specific
  167.     ODNVMethod    ODOSType    GetPlatformType();                    // Macintosh specific
  168.     ODNVMethod    void        SetPlatformType(ODOSType fileType);    // Macintosh specific
  169.     ODNVMethod    ODContainerType        GetContainerType();
  170.     ODNVMethod    void        SetContainerType(ODContainerType containerType);
  171.     ODNVMethod    ODPtr        ReadResourcePtr(ODPlatformType resType, ODSShort resID, ODULong* size); // Mac
  172.     ODNVMethod    void        WriteResourcePtr(ODPlatformType resType, ODSShort resID, 
  173.                                             const void *resPtr, ODULong size); // Mac
  174.     ODNVMethod    void        DeleteResource(ODPlatformType resType, ODSShort resID); // Mac
  175.     inline        ODFileSpec&    GetFileSpec();
  176.     ODNVMethod    void        MoveRename( ODFileSpec* newSpec, ODBoolean isDuplicate ) ;
  177.     ODNVMethod    void        Move( ODSLong targetParID ) ;
  178.     ODNVMethod    void        UniquifyName( ODSShort uniquifyingStringID,
  179.                                             StringHandle uniquifyingString,
  180.                                             ODSShort uniquifyingNumberID,
  181.                                             StringHandle uniquifyingNumberString,
  182.                                             short copyCount,
  183.                                             PFUniquifyAction action,
  184.                                             ODBoolean forceNewName);
  185.     ODNVMethod    void        MoveToTrash() ;
  186.     ODNVMethod    void        Rename( Str63 name ) ;
  187.     ODNVMethod    ODTime        GetFileModDate();
  188.     ODNVMethod    void        SetFileModDate(ODTime date);
  189.     ODNVMethod    ODTime        GetFileCreationDate();
  190.     ODNVMethod    void        SetFileCreationDate(ODTime date);
  191.     ODNVMethod    ODULong     GetAllocationBlockSize();
  192.     ODNVMethod    void        BumpFolderModDate();
  193.     
  194.     ODNVMethod    ODBoolean    IsInTrash( );
  195.  
  196. // Methods you must call while the file is open    
  197.     ODNVMethod    void        Close();
  198.  
  199.     ODNVMethod    void        SetFilePos(ODSShort posMode, ODSLong posOff);
  200.     ODNVMethod    ODSLong        GetFilePos();
  201.  
  202.     ODNVMethod    void        Read(void* buffer, ODSLong* count);
  203.     ODNVMethod    void        Write(const void* buffer, ODSLong* count);
  204.  
  205.     ODNVMethod    ODSLong        GetEndOfFile();
  206.     ODNVMethod    void        SetEndOfFile(ODSLong length);
  207.  
  208.     inline        ODFileRefNum    GetFileRefNum();
  209.  
  210.     ODNVMethod    void        CopyFrom( PlatformFile* src );
  211.         
  212.  
  213. public:
  214.     ODNVMethod    ODError        GetLocalPaths(
  215.                               ODForkType fork,
  216.                               ODULong *refNumCount,
  217.                               ODFileRefNumPtr *refNums);
  218.  
  219. /*    Determine if local access paths to a file fork are open.
  220.     The GetLocalPaths function looks through the FCB list to see if
  221.     the fork of the file specified by spec and fork is open by the 
  222.     local File Manager (you should use PBGetCatInfo and check
  223.     ioFlAttrib if you need to see if *anyone* has the file fork open
  224.     *anywhere*). If the result is noErr, GetLocalPaths returns a
  225.     count and a pointer to an array of file refNums (if count is
  226.     not zero) of local access paths to the specified file fork.
  227.  
  228.     spec        input:    An FSSpec record specifying the file.
  229.     fork        input:    Specifies the file fork - either kDataFork
  230.                         or kResourceFork.
  231.     refNumCount    output:    The number of local access paths found.
  232.     refNums        output: If not NULL, a pointer to an array of
  233.                         file refNums - the number of which is
  234.                         specified by refNumCount.  The caller is
  235.                         responsible for disposing of this pointer.
  236. */
  237.  
  238. private:
  239.     ODNVMethod    void        GetFileID( );
  240.     ODNVMethod    void        UpdateSpecFromID( );
  241.     ODNVMethod    ODBoolean    ActivateResourceFile( ODBoolean &needToCloseResFile );
  242.     
  243.     ODNVMethod    ODFileRefNum GetFirstLocalPath( ODForkType fork );
  244.  
  245.  
  246. private:
  247.  
  248.     ODFileSpec            fFileSpec;
  249.     ODSShort            fDataRefNum;
  250.     ODFilePermission    fPermission;
  251.     ODContainerType        fContainerType;
  252.     ODOSType            fCreator;
  253.     ODOSType            fFileType;
  254.     ODScriptCode        fScriptTag;
  255.     ODULong                fFileID;
  256.     ODULong                fVolModDate;
  257.     ODULong                fTimeLastChecked;
  258.     ODFileRefNum        fResRefNum;
  259.     ODULong                fResOpenStack;
  260.     ODBoolean            fNeedToClose;
  261.     
  262.     friend class CWithActiveResources;
  263. };
  264.  
  265.  
  266. //------------------------------------------------------------------------------
  267. // Inline method bodies
  268. //------------------------------------------------------------------------------
  269.  
  270.  
  271. inline ODULong PlatformFile::GetAsciiNameLength()
  272. {
  273.     return fFileSpec.name[0];
  274. }
  275.  
  276. void PlatformFile::SetPermission(ODFilePermission permission)
  277. {
  278.     fPermission = permission;
  279. }
  280.  
  281. inline ODFileSpec& PlatformFile::GetFileSpec()
  282. {
  283.     return fFileSpec;
  284. }
  285.  
  286. inline ODFileRefNum PlatformFile::GetFileRefNum()
  287. {
  288.     return fDataRefNum;
  289. }
  290.  
  291. inline void PlatformFile::SetFileRefNum( ODFileRefNum refNum )
  292. {
  293.     fDataRefNum = refNum;
  294. }
  295.  
  296.  
  297. #ifdef PRAGMA_INTERNAL_SUPPORTED
  298. #pragma internal reset
  299. #endif
  300.  
  301. #endif // _PLFMFILE_
  302.